<template>
  <!-- 底部部分 => list有数据的时候，才展示  list.length > 0 -->
  <footer class="footer" v-show="list.length">
    <span class="todo-count"
      ><strong>{{ remainder }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li>
        <a
          href="#/"
          @click="ChangeState('all')"
          :class="{ selected: state === 'all' }"
          >全部</a
        >
      </li>
      <li>
        <a
          href="#/active"
          @click="ChangeState('active')"
          :class="{ selected: state === 'active' }"
          >进行中</a
        >
      </li>
      <li>
        <a
          href="#/completed"
          @click="ChangeState('completed')"
          :class="{ selected: state === 'completed' }"
          >已完成</a
        >
      </li>
    </ul>
    <!-- 有已完成的任务，才需要显示这个按钮 -->
    <button
      v-show="list.filter((item) => item.flag).length"
      class="clear-completed"
      @click="DelAll"
    >
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  data() {
    return {
      LengthAll: 0,
    };
  },
  props: { list: Array, state: String },
  computed: {
    remainder() {
      return this.list.filter((item) => item.flag === false).length;
    },
  },
  methods: {
    DelAll() {
      this.$emit("DelAll");
    },
    ChangeState(value) {
      this.$emit("ChangeState", value);
    },
  },
};
</script>

<style></style>
